package games.ninJumpDx.ui.actions
{
	import games.ninJumpDx.data.GameData;
	import games.ninJumpDx.data.UIConfig;
	import utils.ActionFactory;
	import games.ninJumpDx.ui.factorys.MunitFactory;
	
	import utils.Cartoon;
	
	public class Gargoyle extends Cartoon
	{
		private var m_actionFactory:ActionFactory;
		private var m_action:MoveUnit;
	 
		private var m_bottom:Number;
		private var m_info:XMLList;	 
		private var m_g:Number = -.2;
		private var m_v:Number = 0;
		public function Gargoyle(name:String)
		{
			super();
			m_actionFactory = new MunitFactory();
			m_action = MoveUnit(m_actionFactory.makeAction(name));
			addChild(m_action);
			m_info = UIConfig.getInfoByName(name);
			
			if(m_info.hasOwnProperty("@scaleX"))
			{
				scaleX = m_info.@scaleX;
			}
			m_v =  GameData.instance.speed ;
		}
		
		override public function update(t:Object=null):void
		{
			if(!start || pause)return;
			if(x > UIConfig.getGameWidth() + width || x < 0)
			{
				destroy();
				return;
			}
			x +=  GameData.instance.speed * scaleX * 1.5 ;
			m_g = -GameData.instance.speed * .1
			m_v += m_g;
			y += m_v;
			
		}
		
		override public function destroy(e:* = null):void
		{
			super.destroy();
			removeChild(m_action)
			m_action.destroy();
			m_actionFactory = null;
			m_action = null;
			m_info = null;
		}
	}
}